// 基础地址
const BASE_URL = 'http://110.41.43.118:3008';

(function() {
	
	let oPhonetd = document.querySelector('.phone-td');
	let oConfirmtd = document.querySelector('.confirm-td');
	let oLoginBtn = document.querySelector('.login_btn');
	
	// 点击登录
	oLoginBtn.onclick = function() {
		if(oPhonetd.value == '' || oConfirmtd.value == ''){
			// 弹框
			alert("用户名或密码不能为空");
			return;
		};
		
		// 校验
		
		// 登录
		yzb.ajax({
			method:'post',
			url:BASE_URL + '/api_user',
			data:{username:oPhonetd.value,password:oConfirmtd.value,status:'login'},
			success(res){
				if(res.code != 0){
					alert('用户名或密码错误');
					return;
				};
				// 登录成功  存储登录状态
				window.localStorage.setItem('username',res.username);
				window.localStorage.setItem('token',res.user_id);
				// 分情况跳转
				let goodsId = yzb.getUrlValue('goodsId');
				let catId = yzb.getUrlValue('catId');
				if(goodsId){
					window.location.href = `goods.html?goodsId=${goodsId}&catId=${catId}`;
				}else{
					// 跳转至首页
				window.location.href = 'index.html';
				}
				
			}
		})
	};
})();